package com.oazon.moco.link.ui;

import java.util.Arrays;

import android.util.Log;

import com.oazon.moco.link.core.LinkEvent;
import com.oazon.moco.link.core.LinkEventListener;
import com.oazon.moco.link.core.source.LinkEventSource;
import com.oazon.moco.link.event.BatteryEvent;
import com.oazon.moco.link.event.BatteryStatus;

public class BatteryEventListener extends LinkEventListener {
	
	private static int chargePercent = 0;
	private static BatteryStatus status;
	
	public BatteryEventListener(LinkEventSource... source) {
		setBlackList(Arrays.asList(source));
	}
	
	@Override
	public void onLinkEvent(LinkEvent event) {
		if (filter((LinkEventSource) event.getSource())
				|| !(event instanceof BatteryEvent)) {
			return;
		}
		final BatteryEvent e = (BatteryEvent) event;
		if (null != e.getState()) {
			setBatteryState(e.getState());
		}

		if (-1 != e.getCharge_percent()) {
			setBatteryPercent(e.getCharge_percent());
		}
	}

	/**
	 * 改变电量百分比
	 * @param charge_percent
	 * 	【0~100】
	 */
	protected void setBatteryPercent(int chargePercent) {
		this.chargePercent = chargePercent;
		Log.d("AboutActivity", "charge:"+chargePercent);
	}

	/**
	 * 改变电池的状态
	 * @param state
	 */
	protected void setBatteryState(BatteryStatus state) {
		this.status = state;
		Log.d("AboutActivity", "BatteryStatus:"+state);
	}

	public static int getChargePercent() {
		return chargePercent;
	}

	public static BatteryStatus getBatteryStatus() {
		return status;
	}
}
